package ntrees.hu.pxinput;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.CornerPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;

public class pxinput extends Activity {
	private String TAG = "pxinput";
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        test003();
    }
    
    public void test001() {
        CycleLine cycle = new CycleLine(100.0f, new Position(50.0f, 100.0f));
        cycle.setRadian(0, 15);
        Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        cycle.draw(canvas);
        ImageView iv = new ImageView(this);
        iv.setBackgroundColor(Color.RED);
        iv.setImageBitmap(bitmap);
        iv.setBackgroundColor(Color.WHITE);
        setContentView(iv);
    }
    
    public void test002() {
    	Path path = makeFollowPath();
    	Paint paint = new Paint();
    	paint.setColor(Color.BLUE);
    	
        Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawPath(path, paint);
        ImageView iv = new ImageView(this);
        iv.setBackgroundColor(Color.RED);
        iv.setImageBitmap(bitmap);
        iv.setBackgroundColor(Color.WHITE);
        setContentView(iv);
    }
    
    public void test003() {
    	//View v = new PathView(this);
    	ArcViewGroup v = new ArcViewGroup(this);
    	v.setOrientation(ArcViewGroup.VERTICAL);
    	v.setCenter(0, 100);
//    	ArcTextView v = new ArcTextView(this, "  A  ", 0, 10, 100);
    	v.addView(new ArcTextView(this, " name "));
    	v.addView(new ArcTextView(this, " is "));
    	v.addView(new ArcTextView(this, " google "));
    	v.addView(new ArcTextView(this, " android "));
    	v.addView(new ArcTextView(this, " hello "));
    	ArcViewGroup v2 = new ArcViewGroup(this);
    	v2.setAngle(0);
    	v2.addView(new ArcTextView(this, " f "));
    	v2.addView(new ArcTextView(this, " g "));
    	v2.addView(new ArcTextView(this, " h "));
    	v.addView(v2);
    	//v.setText("T-------T");
    	//v.setLength(100);
//    	v.setSweepAngle(360);
//    	v.setAngle(90);
    	//v.setWidth(10);
    	v.setRadius(100);
    	v.setFocusable(true);
        setContentView(v);
        v.requestFocus();
    }
    
    private static Path makeFollowPath() {
        Path p = new Path();
//        p.moveTo(0, 0);
//        for (int i = 1; i <= 15; i++) {
//            p.lineTo(i*20, (float)Math.random() * 35);
//        }
        RectF rectf = new RectF();
        rectf.top = 0;
        rectf.left = 0;
        rectf.right = 200;
        rectf.bottom = 400;
        p.addArc(rectf, 60, 120);
        return p;
    }
    
    class PathView extends View {
    	Paint paint;
    	Path path;
    	Paint paint2;
		public PathView(Context context) {
			super(context);
	    	paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	    	paint.setColor(Color.BLUE);
	    	paint.setStyle(Paint.Style.STROKE);
	    	paint.setStrokeWidth(32);
	    	paint.setPathEffect(new CornerPathEffect(10));
	    	
	    	path = makeFollowPath();

	    	paint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
	    	paint2.setColor(Color.WHITE);
	    	paint2.setTextSize(20);
	    	paint2.setStrokeWidth(3);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			canvas.drawColor(Color.LTGRAY);
	    	canvas.drawPath(path, paint);
	    	canvas.drawTextOnPath("SAAAAAAAAAAAAE", path, 0, 10, paint2);
		}
		
		@Override
		public boolean dispatchKeyEvent(KeyEvent event) {
			if (event.getAction() == KeyEvent.ACTION_DOWN)
				paint.setColor(Color.BLACK);
			else
				paint.setColor(Color.BLUE);
			invalidate();
			return true;
		}
    }
    
    class CycleView extends View {
    	CycleLine cycle;
    	
		public CycleView(Context context) {
			super(context);
	        cycle = new CycleLine(100.0f, new Position(100.0f, 200.0f));
	        cycle.setRadian(0, 360);
		}
		
		@Override
		protected void onDraw(Canvas canvas) {
			cycle.draw(canvas);
		}
    }
}